package com.peng.wx_official_account.controller;

import com.peng.wx_official_account.entity.pojo.WxPushUser;
import com.peng.wx_official_account.service.WxPushUserService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

@RestController
@RequestMapping("wx")
public class WxPushUserController {

    private final WxPushUserService service;

    public WxPushUserController(WxPushUserService service) {
        this.service = service;
    }

    @PostMapping("user")
    public WxPushUser addWxPushUser(@RequestBody WxPushUser wxPushUser) {
        wxPushUser.setCreatedAt(LocalDateTime.now()).setUpdatedAt(LocalDateTime.now());
        return service.save(wxPushUser) ? wxPushUser : null;
    }

}
